package de.baumann.browser.activitys

import android.content.Context
import android.content.Intent
import android.preference.PreferenceManager
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import kotlinx.android.synthetic.main.activity_engine.*
import kotlinx.android.synthetic.main.include_tool_bar.*

class EngineActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    companion object {
        fun startEngineActivity(context: Context) {
            context.startActivity(Intent(context, EngineActivity::class.java))
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_engine
    }

    override fun getTitleText(): String {
        return "默认搜索引擎"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        val sp = PreferenceManager.getDefaultSharedPreferences(mContext)
        var value = sp.getInt(mContext.getString(R.string.sp_search_engine), 0)
        when (value) {
            0 -> rbBaidu.isChecked = true
            1 -> rbBing.isChecked = true
            2 -> rbGoogle.isChecked = true
        }

        rgEngine.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                R.id.rbBaidu -> value = 0

                R.id.rbBing -> value = 1

                R.id.rbGoogle -> value = 2
            }
            val editor = sp.edit()
            editor.putInt(mContext.getString(R.string.sp_search_engine), value)
                    .apply()
        }
    }

    override fun initData() {
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }
}
